<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-police__policeserviceappointment}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.keyWord" placeholder="请输入报名人姓名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.activityeId" clearable placeholder="请选择活动">
            <el-option
              v-for="item in activityTitleOptions"
              :key="item.id"
              :label="item.title"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" clearable placeholder="请选择审核状态">
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="activityTitle" label="活动名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="creatorName" label="报名人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="审核状态" header-align="center" align="center">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.status == 0" size="small" type="info">待审核</el-tag>
                <el-tag v-else-if="scope.row.status == 1" size="small" type="success">审核已通过</el-tag>
                <el-tag v-else-if="scope.row.status == 2" size="small" type="warning">审核未通过</el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="createDate" label="报名时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status == 0" type="text" size="small" @click="approvedService(scope.row)">审核通过</el-button>
            <el-button v-if="scope.row.status == 0" type="text" size="small" @click="reviewFailedService(scope.row)">审核不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/creditWarning/activitysignup/page',
        getDataListIsPage: true,
        exportURL: '/creditWarning/activitysignup/export',
        deleteURL: '/creditWarning/activitysignup',
        deleteIsBatch: true
      },
      dataForm: {
        keyWord: '',
        activityeId: '',
        status: ''
      },
      activityTitleOptions: [],
      statusOptions: [
        {
          "label": '待审核',
          "value": 0,
        },
        {
          "label": '审核已通过',
          "value": 1,
        },
        {
          "label": '审核未通过',
          "value": 2,
        }
      ]
    }
  },
  created() {
    this.getActivityTitleOptions()
  },
  methods: {
    // 获取所有活动下拉框
    getActivityTitleOptions() {
      this.$http.get('/creditWarning/activity/list').then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.activityTitleOptions = res.data
      }).catch(() => {})
    },
    // 审核通过
    approvedService(row) {
      this.$http.put('/creditWarning/activitysignup', {
        id: row.id,
        activityeId: row.activityeId,
        creator: row.creator,
        status: 1
      }).then(({ data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.getDataList()
      })
    },
    // 审核不通过
    reviewFailedService(row) {
      this.$http.put('/creditWarning/activitysignup', {
        id: row.id,
        activityeId: row.activityeId,
        creator: row.creator,
        status: 2
      }).then(({ data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.getDataList()
      })
    }
  }
}
</script>
